package com.qkl.upload.publics.web.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Slf4j
@Configuration
public class AppWebConfig extends WebMvcConfigurationSupport {

    @Autowired
   private HandlerInterceptor appInterceptor;

    @Value("${root.uploadPath}")
    private String uploadPath;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("============addInterceptors.");
        //registry.addInterceptor(appInterceptor).addPathPatterns("/*","/*/*");
        registry.addInterceptor(appInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        String basePath = "file:" + uploadPath;
        log.info("=====addResourceHandlers.basePath={}",basePath);
        registry.addResourceHandler("/downloadApi/**").addResourceLocations(basePath);
        super.addResourceHandlers(registry);
    }
}
